package com.xb.loan.cashier.biz.job;
import com.xb.loan.cashier.biz.dao.bean.CashierPayChannel;
import com.xb.loan.cashier.biz.service.CashierPayChannelService;
import com.xb.loan.cashier.service.constant.ICashierEnumConst;
import com.xb.loan.util.DateHelper;
import com.xb.loan.util.qrtz.task.AbstractCronTask;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 第三方提现对账任务
 */
public class ThirdAccountChargeJob extends AbstractCronTask {
    private static final Logger log = LoggerFactory.getLogger(ThirdAccountChargeJob.class);

    private CashierPayChannelService cashierPayChannelService;
    
    @Override
    public void run() {
    	log.info("ThirdAccountChargeJob run 第三方充值对账开始");
        if(cashierPayChannelService==null){
            cashierPayChannelService = getSpringBean("cashierPayChannelService");
        }
        List<CashierPayChannel> channels = cashierPayChannelService.selectByPayType(ICashierEnumConst.CashierPayType.charge.getCode());
        if(CollectionUtils.isEmpty(channels)){
            log.info("msg=第三方渠道为空，不进行对账");
            return;
        }
        for(CashierPayChannel channel : channels){
            Date date = DateHelper.getBeforeDay(new Date(), -1);
            String day = DateHelper.formatDate("yyyyMMdd", date);
            ThirdAccountChargeChannelJob job = new ThirdAccountChargeChannelJob();
            Map<String, Object> params = new HashMap<String, Object>();
            job.setParams(params);
            job.setJobName("TCA_"+day+"_"+channel.getPayChannelId());
            params.put("channel", channel);
            params.put("accountDayThird", day);
            getTaskScheduleManager().shedule(job);
        }
    }

    public void setCashierPayChannelService(CashierPayChannelService cashierPayChannelService) {
        this.cashierPayChannelService = cashierPayChannelService;
    }

}
